package com.itheima.zhuanhuan;

import com.itheima.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;

/*

treeSet

 */
public class Test01 {


    public static void main(String[] args) {
        // method1();
        // 年龄的降序 和姓名的降序
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o2.getAge() - o1.getAge();
                result = result == 0 ? o2.getName().compareTo(o1.getName()) : result;
                return result;
            }
        });
       /* TreeSet<Student> ts = new TreeSet<>((o1,o2)->{
            int result=o2.getAge()-o1.getAge();
            result=result==0?o2.getName().compareTo(o1.getName()):result;
            return result;
        });*/
        Student lu = new Student("鹿晗", 28);
        Student guan = new Student("关晓彤", 22);
        Student wu = new Student("吴亦凡", 27);
        Student cai = new Student("蔡徐坤", 28);
        ts.add(lu);
        ts.add(guan);
        ts.add(wu);
        ts.add(cai);
        System.out.println(ts);
        ts.forEach(t -> System.out.println(t));
    }
    /*
    使用年龄升序  姓名升序
     */
    private static void method1() {
        TreeSet<Student> ts = new TreeSet<>();
        Student lu = new Student("鹿晗", 28);
        Student guan = new Student("关晓彤", 22);
        Student wu = new Student("吴亦凡", 27);
        Student cai = new Student("蔡徐坤", 28);
        ts.add(lu);
        ts.add(guan);
        ts.add(wu);
        ts.add(cai);
        System.out.println(ts);
    }


}
